/*
 * @lc app=leetcode.cn id=1854 lang=javascript
 *
 * [1854] 人口最多的年份
 */

// @lc code=start
/**
 * @param {number[][]} logs
 * @return {number}
 */
var maximumPopulation = function (logs) {
  let arr = Array(100).fill(0);
  let max = 0, year = 2050;
  logs.forEach(([start, end]) => {
    for (let i = start - 1950; i < end - 1950; i++) {
      arr[i]++;
      if (arr[i] === max) {
        year = Math.min(year, i);
      } else if (arr[i] > max) {
        max = arr[i];
        year = i;
      }
    }
  })
  return year + 1950;
};
// @lc code=end
